package com.zzxx.userManagement.dao.impl;

import com.zzxx.userManagement.dao.UserDao;
import com.zzxx.userManagement.domain.User;
import com.zzxx.userManagement.utils.DruidUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class UserDaoImpl implements UserDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public User findUserByNameAndPwd(String user, String password) {
        String sql = "select * from user where username = ? and password = ?";
        List<User> list = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(User.class), user, password);
        return list.size() != 0 ? list.get(0) : null;
    }
}
